<template>
  <el-dialog
    draggable
    overflow
    :title="'查看开卡'"
    v-model="visible"
    :width="1024"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="dialogForm"
      label-width="80px"
      label-position="right"
    >
      <el-row>
        <el-col :span="6" align="客户">
          <el-form-item label="客户" prop="customer_id">
            <el-input v-model="form.customer.code" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="工艺">
            <el-input v-model="form.craft_remark" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="6"> </el-col>

        <el-col :span="6">
          <el-form-item label="贴合间隙" prop="joint_gap">
            <el-input v-model="form.joint_gap" />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="终检">
            <el-checkbox
              v-model="form.needEndInspect"
              label=""
              :true-label="1"
              :false-label="0"
            />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="客供底布">
            <el-checkbox
              v-model="form.customer_material"
              label=""
              :true-label="1"
              :false-label="0"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="正面" prop="inspection_requirements">
            <el-input v-model="form.inspection_requirements" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="生管要求" prop="packaging_requirements">
            <el-input v-model="form.newremark" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="上胶间隙" prop="glue_gap">
            <el-input v-model="form.glue_gap" />
          </el-form-item>
        </el-col>
        <el-col :span="18">
          <el-form-item label="工艺记录" prop="process_requirements">
            <el-input v-model="form.process_requirements" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="油温" prop="oil_temperature">
            <el-input v-model="form.oil_temperature" />
          </el-form-item>
        </el-col>
        <el-col :span="18">
          <el-form-item label="备注" prop="remark">
            <template #default>
              <div style="border: 1px solid gray; width: 100%; height: 100%">
                {{ form.remark }}
              </div>
            </template>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="胶温" prop="glue_temperature">
            <el-input v-model="form.glue_temperature" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="开卡面布" prop="details">
            <sc-VxeTable
              ref="xGrid1"
              :gridEvts="gridEvents"
              :gridOps="gridOps"
              :data="form.details"
              :tablecode="'market_pro_storage_receive_save'"
            >
            </sc-VxeTable>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="工艺BOM" prop="bom_id">
            <skAutoChoose
              style="width: 100%"
              ref="autoBom"
              :asKey="'bom_id'"
              :assign="form"
              v-model="form.bom.name"
              :name="'bom'"
              :placeholder="'请选择加工物料'"
            >
            </skAutoChoose>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="BOM明细" prop="raws">
            <sc-VxeTable
              ref="xGrid1"
              :gridEvts="gridEvents"
              :gridOps="gridOps"
              :data="form.raws"
              :tablecode="'market_pro_process_save'"
            >
            </sc-VxeTable>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <!-- <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button> -->
    </template>
  </el-dialog>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import skAutoChoose from "@/components/skAutoChoose";
import skAutodcomplete from "@/components/skAutoComplete";
export default {
  emits: ["success", "closed"],
  components: { skDicSelect, skAutoChoose, skAutodcomplete },
  data() {
    return {
      gridEvents: {},
      gridOps: { height: 200 },
      linkmanList: [],
      form: {
        process_route: {},
        details: [],
        raws: [],
        bom: {},
        customer: {},
        linkman: { name: "" },
        linkman_id: "",
        salesman: { name: "" },
        employee: { name: "" },
      },
      rules: {},
      visible: false,
      isSaveing: false,
    };
  },
  mounted() {},
  methods: {
    open() {
      this.visible = true;
      return this;
    },
    setData(id) {
      this.getData(id);
      return this;
    },
    getProcessCtegory() {
      return {
        category_id: this.form.craft_category_id,
        "details.process.content": {
          type: this.form.needEndInspect == 1 ? "lk" : "nl",
          value: "终检",
        },
      };
    },
    getData(ids) {
      this.$API.pro.OpenCard.info
        .get({ filter: [{ id: { type: "eq", value: ids } }] })
        .then((res) => {
          console.log(res.data);
          this.form.newremark = res.data.details[0].newremark;

          Object.assign(this.form, this.$TOOL.removeNull(res.data));
        });
    },

    resetForm() {},
    processSelect(data) {
      this.form.raws = (data.details ?? [])
        .filter((v) => v.process.hasbom_id == 1)
        .map((v) => {
          delete v.id;
          return v;
        });
      this.form.process_route = data;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.pro.OpenCard.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },
    handleSuccess(data) {
      this.linkmanList.push(data);
      this.form.linkman_id = data.id;
    },
  },
};
</script>
